package com.example;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

@Service
@Slf4j
public class MyTask {

    @Autowired
    private UserRepository userRepository;

    @Scheduled(fixedRate = 5000)
    @Transactional
    public void autoCreateUser() {
        User user = User.builder().name(UUID.randomUUID().toString()).build();
        User saveUser = userRepository.save(user);
        log.info("saveUser:{}", saveUser.getId());
    }
}
